<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
echo '<i>' . $model->userCreated->fullname . '</i><br>';
echo '<i>' . $model->created_at . '</i><br>';
echo '<b>' . $model->title . '</b><br>';
$checkLike = BlogLike::model()->find("blog_id = :blog_id and user_id =:user_id", array(
        ':blog_id' => $model->id,
        ':user_id' => Yii::app()->user->id
    ));
if ($checkLike) {
        ?>
        <a href="#" class="like_link"
           onclick="return like(<?php echo $model->id; ?>);">Bỏ thích</a><br>
       <?php } else {
           ?>
        <a href="#" class="like_link"
           onclick="return like(<?php echo $model->id; ?>);">Thích</a><br>
           <?php
       }
echo $model->content;
if ($allComment != null && sizeof($allComment) > 0) {
    echo '<h2>Bình luận</h2>';
    foreach ($allComment as $cm) {
        echo '<b>' . $cm->user->fullname . '</b><br>';
        echo 'Lúc : ' . Format::timeAgo($cm->comment_at, 'Y-m-d H:i:s') . '<br>';
        echo CHtml::encode($cm->content) . '<br><hr>';
    }
} else {
    echo 'Chưa có bình luận nào.';
}
?>
<h1>Bình luận</h1>
<div class="form">
    <?php
    $form = $this->beginWidget('CActiveForm', array(
        'id' => 'comment-form',
        'action' => array(
            'blog/comment/' . $model->id
        ),
        'clientOptions' => array(
            'validateOnSubmit' => true
        )
    ));
    ?>
    <p class="note">
        Fields with <span class="required">*</span> are required.
    </p>
    <div class="row">
        <?php echo $form->labelEx($comment, 'content'); ?>
        <?php echo $form->textArea($comment, 'content'); ?>
        <?php echo $form->error($comment, 'content'); ?>
    </div>
    <div class="row buttons">
        <?php echo CHtml::submitButton('Đăng'); ?>
    </div>
    <?php $this->endWidget(); ?>
</div>
<script type="text/javascript">
    function like(id) {
        $.ajax({
            url: "<?php echo Yii::app()->createUrl('blog/like') . '?id='; ?>" + id,
            type: 'GET',
            success: function(data) {
                var json = eval('(' + data + ')');
                $("a.like_link").text(json['meg']);
                $("p.like_cnt_" + id).text(json['like_cnt']);
            }
        });
        return false;
    }
</script>

